package com.fuhao.springbootactivemq.controller;

import com.fuhao.springbootactivemq.Model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessagePostProcessor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Destination;

/**
 * @author zhang
 * @title: SendMessageController
 * @projectName springboot-activemq
 * @description: TODO
 * @date 2019/5/1718:01
 */
@RestController
public class SendMessageController {

    @Autowired
    @Qualifier("jmsQueueTemplate")
    private JmsTemplate jmsQueueTemplate;

    @Autowired
    @Qualifier("jmsTopicTemplate")
    private JmsTemplate jmsTopicTemplate;

    /**
     * queue模式
     */
    @RequestMapping("/queue1Send")
    public void sendQueueMessage(String destination) {
        jmsQueueTemplate.convertAndSend(destination,new User(1,"张三",12));
    }

    /**
     * topic模式
     */
    @RequestMapping("/topic1Send")
    public void sendTopicMessage(String destination) {
        jmsTopicTemplate.convertAndSend(destination,new User(2,"李四",18));
    }
}
